//
// Created by 86176 on 2021/11/24.
//

#include <iostream>
#include "MyIohander.h"
#include "MyMessage.h"

void MyIohander::sessionCreated(Session *session) {
//    std::cout<<"session������֮ǰ����sessionCreated����."<<std::endl;

}


void MyIohander::sessionClosed(Session *session) {
    //std::cout<<"session������֮ǰ����sessionClosed����."<<std::endl;
    std::cout<<"��д�ģ�session������֮ǰ����sessionClosed����."<<std::endl;
}

void MyIohander::messageSent(Session *session, Message *message) {

}

void MyIohander::messageReceived(Session *session, Message *message) {
    //std::cout<<"Iohander:"<<session->ioBuffer->byteStream;
    //
    if(NULL == message) return;
    MyMessage * myMessage = (MyMessage *)message;
    std::cout<<"(Iohander:)"<<std::endl;
    std::cout<<"idFrom:"<<myMessage->idFrom<<std::endl;
    std::cout<<"idTo:"<<myMessage->idTo<<std::endl;
    std::cout<<"type:"<<(int)myMessage->type<<std::endl;
    std::cout<<"data:"<<myMessage->contect<<std::endl;

    //
    MyMessage *messageSend = new MyMessage();
    memcpy(messageSend->idFrom, myMessage->idTo, strlen(myMessage->idTo));
    memcpy(messageSend->idTo, myMessage->idFrom, strlen(myMessage->idTo));
    char backType = '2';
    memcpy(&(messageSend->type), &backType, 2);
    messageSend->contect = "成功刚收消息";
    //std::cout<<"here";
    std::cout<<"coutData:"<<messageSend->contect<<std::endl;
    messageSent(session,message);

    delete(message);
}

void MyIohander::sessionIdle(Session var1, IdleStatus var2) {

}

